package cn.livingCloud.controller.content;

import cn.livingCloud.dto.ReplyRuleDto;
import cn.livingCloud.dto.ReplyRuleListDto;
import cn.livingCloud.service.ReplyRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by sujiantang on 2015/12/9.
 */
@Controller
@RequestMapping("/admin/wechat")
public class ReplyRuleController {
    @Autowired
    private ReplyRuleService ruleService;

    @RequestMapping("/reply_rule_list.htm")
    public String getReplyRuleList(ReplyRuleListDto formDto, Model model) {
        ruleService.findReplyRuleList(formDto);
        model.addAttribute("formDto", formDto);
        return "wechat/reply_rule/reply_rule_list";
    }

    @RequestMapping("/change_state")
    public String changeState(String uuid, boolean state, Model model) {
        ReplyRuleDto formDto = ruleService.updateState(uuid, state);
        model.addAttribute("formDto", formDto);
        return "wechat/reply_rule/reply_rule_list_item";
    }

    //处理删除
    @RequestMapping(value = "/reply_rule_delete", method = RequestMethod.POST)
    public String delete(String uuid) {
        ruleService.delete(uuid);
        return "redirect:reply_rule_list.htm?delete=success";
    }

    @RequestMapping("/search_rule")
    @ResponseBody
    public List<ReplyRuleDto> searchRule(String key) {
        return ruleService.searchRuleList(key);
    }

}
